<?php
/**
 * Created by Lgq.
 * User: Administrator
 * Date: 2018/4/18
 * Time: 22:04
 */
namespace console\controllers;
use yii\console\Controller;
use common\models\Order;
use common\models\OrderLog;

class ToproblemController extends Controller{
    public function actionIndex(){
        //这里无法获取session  考虑不用模型处理了，直接用原生态SQL语句update
        $time_seconds = time()-3600*24*2;
        $problems = Order::find()
            ->where(['status' => [1]])
            ->andWhere(['<', 'dispatch_at', $time_seconds])
            ->orderBy('order_id')
            ->all();

        foreach ($problems as $problem){
            //echo $problem->title."\n";
            $problem->status = 10;
            $res= $problem->save(false);   //这里执行异常是因为引入的发消息命令里有session是获取不到的，发消息的接口也要改，加上定时任务再
            if($res){
                //增加转入疑难问题记录
                $order_log = new OrderLog();
                //由管理员转入疑难问题  定时执行
                $order_log->uid=1;
                $order_log->isadmin=1;

                $order_log->order_id = $problem->order_id;
                $order_log->deallog = '转入疑难问题';
                $order_log->opstatus=6;
                $order_log->save();
            }
        }
        return ExitCode::OK;
    }

    public function actionGetdata($name){
        echo 'get data from u8 '.$name;
    }
}
